package com.bw.shop2208a.adapter

import android.graphics.Color
import android.widget.ImageView
import android.widget.TextView
import com.bw.shop2208a.R
import com.bw.shop2208a.entity.DataXGoodsTypeEntity
import com.bw.shop2208a.utils.GlideUtils
import com.chad.library.adapter.base.BaseQuickAdapter
import com.chad.library.adapter.base.viewholder.BaseViewHolder

class GoodsTypeTwoAdapter() : BaseQuickAdapter<DataXGoodsTypeEntity, BaseViewHolder>(R.layout.item_goods_type_two) {
    private var selectedPosition = 0
    override fun convert(holder: BaseViewHolder, item: DataXGoodsTypeEntity) {
        holder.setText(R.id.tv,item.category_name)
        var iv = holder.getView<ImageView>(R.id.iv)
        item.category_icon?.let { GlideUtils.loadImage(context,iv, it) }
        if (holder.adapterPosition == selectedPosition){
            holder.itemView.setBackgroundColor(Color.BLACK)
            holder.getView<TextView>(R.id.tv).setTextColor(Color.WHITE)
        }else{
            holder.itemView.setBackgroundColor(Color.WHITE)
            holder.getView<TextView>(R.id.tv).setTextColor(Color.BLACK)
        }
    }
    fun setselectedPosition(positon:Int){
        selectedPosition = positon
        notifyDataSetChanged()
    }
}